package com.gali.lovefinder.controller;

import com.gali.lovefinder.common.BaseResponse;
import com.gali.lovefinder.common.ErrorCode;
import com.gali.lovefinder.common.ResultUtils;
import com.gali.lovefinder.model.bo.report.AddReportBO;
import com.gali.lovefinder.model.request.report.AddReportRequest;
import com.gali.lovefinder.service.ReportService;
import com.gali.lovefinder.utils.AssertUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author wangyan203
 */
@RestController
@RequestMapping("/report")
public class ReportController {
    @Resource
    private ReportService reportService;

    @PostMapping("/addReport")
    public BaseResponse<Void> addReport(@RequestBody AddReportRequest addReportRequest) {
        AssertUtil.isNull(addReportRequest.getContent(), ErrorCode.PARAMS_ERROR);
        AssertUtil.isNull(addReportRequest.getReportedId(), ErrorCode.PARAMS_ERROR);
        AssertUtil.isNull(addReportRequest.getReportedUserId(), ErrorCode.PARAMS_ERROR);

        AddReportBO addReportBO = new AddReportBO();
        BeanUtils.copyProperties(addReportRequest, addReportBO);

        reportService.addReport(addReportBO);

        return ResultUtils.success(null);
    }

    @GetMapping("/approve/{reportId}")
    public BaseResponse<Void> approveReport(@RequestParam("reportId") @PathVariable("reportId") String reportId) {
        reportService.approveReport(reportId);
        return ResultUtils.success(null);
    }
}
